<html>
<head><meta charset="utf-8"><title>Add relational operators to std · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Add.20relational.20operators.20to.20std.html">Add relational operators to std</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182050021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Add%20relational%20operators%20to%20std/near/182050021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Add.20relational.20operators.20to.20std.html#182050021">(Nov 27 2019 at 19:16)</a>:</h4>
<p>Can we add relational operators to libcore, e.g., </p>
<div class="codehilite"><pre><span></span><span class="c1">// in core::ops</span>
<span class="k">trait</span><span class="w"> </span><span class="n">LessThan</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">type</span> <span class="nc">Target</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="k">fn</span> <span class="nf">less_than</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">RHS</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Self</span>::<span class="n">Target</span><span class="p">;</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">impl</span><span class="o">&lt;</span><span class="n">T</span>: <span class="nb">PartialOrd</span><span class="o">&gt;</span><span class="w"> </span><span class="n">LessThan</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">   </span><span class="k">type</span> <span class="nc">Target</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kt">bool</span><span class="p">;</span><span class="w"></span>
<span class="w">   </span><span class="cm">/* dispatch to partial ord */</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>?</p>
<p>Or are any design issues that make this impossible?</p>



<a name="182053761"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Add%20relational%20operators%20to%20std/near/182053761" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> XAMPPRocky <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Add.20relational.20operators.20to.20std.html#182053761">(Nov 27 2019 at 19:59)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> I don't know about libcore specifically but these are available in typenum. <a href="https://docs.rs/typenum/1.11.2/typenum/type_operators/index.html" target="_blank" title="https://docs.rs/typenum/1.11.2/typenum/type_operators/index.html">https://docs.rs/typenum/1.11.2/typenum/type_operators/index.html</a></p>



<a name="182053898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Add%20relational%20operators%20to%20std/near/182053898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Add.20relational.20operators.20to.20std.html#182053898">(Nov 27 2019 at 20:01)</a>:</h4>
<p>For clarification: do you want the <code>&lt;</code>, <code>&gt;=</code>, etc. operators to desugar to those new traits instead of PartialOrd? If not, I don't really see the point of adding them.</p>



<a name="182054273"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Add%20relational%20operators%20to%20std/near/182054273" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Add.20relational.20operators.20to.20std.html#182054273">(Nov 27 2019 at 20:06)</a>:</h4>
<blockquote>
<p>Do you want the &lt;, &gt;=, etc. operators to desugar to those new traits instead of PartialOrd?</p>
</blockquote>
<p>Yes.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>